//  创建切片
import { createSlice, PayloadAction } from '@reduxjs/toolkit';

// 定义初始的数据类型
interface stateType {
    count: number
}

// 定义初始的数据
const initialState: stateType = {
    count: 0
}

// 定义shop购物车切片
export const shopSlice = createSlice({
    name: 'shop',
    initialState,
    reducers: {
        addcount(state) {
            state.count += 1
        },
        jiancount(state, actions: PayloadAction<number>) {
            state.count -= actions.payload  // payload 类型只能是number
        }
    }
})

//页面中使用该方法实现操作修改rtk仓库中的count数据
export const { addcount, jiancount } = shopSlice.actions;

// 导出reducer
export default shopSlice.reducer

